<?php

// 品牌表

namespace  app\console\model;

use think\Model;
use app\console\model\Shop as ShopModel;
use app\console\model\BrandType as BrandTypeModel;

class Brand extends Model
{
    // protected function getTypeNameAttr($value, $data)
    // {
    //
    //     $TypeName = (new BrandTypeModel)->where(['id' => $data['type_id']])->value('title');
    //
    //     return $TypeName;
    // }

    protected function getShopNameAttr($value, $data)
    {

        $ShopName = (new ShopModel)->where(['member_id' => $data['shop_id']])->value('title');

        return $ShopName;
    }

    // 模型事件
    protected static function init()
    {
        // 写入前
        self::event('before_write', function ($data) {
            $data->picUrl = uploadImg('picUrl', 'shop');
            $data->update_time = date('Y-m-d', time());
        });
    }
}